using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Atom.Data.ManagerObjects;
using Atom.Data.BusinessObjects;
using Atom.Data.Base;

namespace Atom.Data.UnitTests
{
	[TestFixture]
    public partial class IBalanceRecordTests : UnitTestbase
    {
        [SetUp]
        public void SetUp()
        {
            manager = managerFactory.GetIBalanceRecordManager();
            manager.Session.BeginTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            manager.Session.RollbackTransaction();
            manager.Dispose();
        }
        
        protected Atom.Data.ManagerObjects.IIBalanceRecordManager manager;
		
		protected Atom.Data.BusinessObjects.IBalanceRecord CreateNewIBalanceRecord()
		{
			Atom.Data.BusinessObjects.IBalanceRecord entity = new Atom.Data.BusinessObjects.IBalanceRecord();
			
			
			entity.Balanceid = "Te";
			entity.Trantype = 57;
			entity.Medicaretype = 19;
			entity.Registerno = "Test Test Test";
			entity.Registertimes = 42;
			entity.Invoiceid = "Test Test Test Tes";
			entity.Clinictype = 78;
			entity.Balancesign = 50;
			entity.Refundsign = 80;
			entity.Medtype = "Test Test Tes";
			entity.Persontype = "Test ";
			entity.Medicareno = "Test Test Tes";
			entity.Cardno = "Test Test Test Test ";
			entity.Medregisterno = "Test Test Test";
			entity.Medtradeno = "Test Test Test Test T";
			entity.Medorderno = "T";
			entity.Operatorid = "Test Test Test Tes";
			entity.Operatedate = System.DateTime.Now;
			entity.Accountbalance = 2;
			entity.Cashpay = 83;
			entity.Accountpay = 41;
			entity.Medicarepay = 55;
			entity.Prepay1 = 91;
			entity.Prepay2 = 7;
			entity.Prepay4 = 1;
			entity.Prepay5 = 39;
			entity.Prepay6 = 73;
			entity.Prepay7 = 84;
			entity.Prepay8 = 62;
			entity.Prepay9 = 69;
			entity.Prepay0 = 51;
			entity.Prepay3 = 44;
			entity.Sickno = "Tes";
			entity.Sickname = "Test Test ";
			entity.Prepay10 = 26;
			entity.Prepay11 = 5;
			entity.Prepay12 = 17;
			entity.Prepay13 = 71;
			entity.Prepay14 = 73;
			entity.Prepay15 = 93;
			entity.Prepay16 = 93;
			entity.Prepay17 = 15;
			entity.Prepay18 = 1;
			entity.Prepay19 = 27;
			entity.Prepay20 = 88;
			
			return entity;
		}
		protected Atom.Data.BusinessObjects.IBalanceRecord GetFirstIBalanceRecord()
        {
            IList<Atom.Data.BusinessObjects.IBalanceRecord> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				Atom.Data.BusinessObjects.IBalanceRecord entity = CreateNewIBalanceRecord();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                Atom.Data.BusinessObjects.IBalanceRecord entityA = CreateNewIBalanceRecord();
				manager.Save(entityA);

                Atom.Data.BusinessObjects.IBalanceRecord entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                Atom.Data.BusinessObjects.IBalanceRecord entityA = GetFirstIBalanceRecord();
				
				entityA.Medicaretype = 42;
				
				manager.Update(entityA);

                Atom.Data.BusinessObjects.IBalanceRecord entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Balanceid, entityB.Balanceid);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                Atom.Data.BusinessObjects.IBalanceRecord entity = GetFirstIBalanceRecord();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

